<template>
	<view class="container">
		<view class="banner">
			<image src="../../../static/fanli/143.png" mode="widthFix" class="pic"></image>
			
			<view class="con">
				<image :src="userInfo.head" mode="" class="avatar"></image>
				<text class="name">{{userInfo.name}}</text>
				<image src="../../../static/fanli/201.png" mode="widthFix" class="icon" v-if="userInfo.rank < 10"></image>
				<image src="../../../static/fanli/202.png" mode="widthFix" class="icon" v-if="userInfo.rank >= 10"></image>
			</view>
		</view>
		
		<view class="new">
			<image :src="buyList.avatar" mode="" class="avatar"></image>
			<text class="name">用户{{buyList.name}}刚刚成为了佳音超级会员</text>
		</view>
		
		<view class="f1">
			<image src="../../../static/fanli/144.png" mode="widthFix" class="pic"></image>
			
			<view class="btn_go" @click="onLevelClick">马上升级</view>
		</view>
		
		<view class="f2">
			<image src="../../../static/fanli/146.png" mode="widthFix" class="pic"></image>
			<view class="ul">
				<view v-for="(item, index) in privilege" :key="index" class="li">
					<text>{{item}}</text>
				</view>
			</view>
			
			<view class="btn_go" @click="onLevelClick">马上升级</view>
		</view>
	</view>
</template>

<script>
	import { runGetLevelupData } from '@/module/api'
	import { avatarUrl, getRandMobile } from '@/common/util'
    import WxNotificationCenter from '@/libs/WxNotificationCenter/wxnotificationcenter'
	
	const _ = require("@/libs/underscore/underscore-min.js")._
	
	export default {
		data() {
			return {
				buyList: {
					avatar: '',
					name: ''
				},
				privilege: [],
				sid: null,
				price: 0,
				sname: "",
				sdesc: ""
			};
		},
		
		computed: {
			shareAppMessage () {
				return this.$store.state.shareAppMessage
			},
			
			userInfo () {
				return this.$store.state.userInfo
			}
		},
		
		onLoad() {
			let _t = this
			
			this.handleRefreshBuyList()
			
			runGetLevelupData({
				params: {
					class: 1
				},
				success: res => {
					if(!_.isEmpty(res.data)){
						_t.price = res.data[0].price
						_t.privilege = res.data[0].desc.split('|')
						_t.sid = res.data[0].id
						_t.sname = res.data[0].description.split('|')[0]
						_t.sdesc = res.data[0].description.split('|')[1]
					}
				}
			})
		},
		
		methods:{
			onLevelClick () {
				if(this.sid == null){
					uni.showToast({
						icon: "none",
						title: "数据加载中"
					})
				}else{
					uni.navigateTo({
						url: "/pages/cart/confirm/confirm?params=" + JSON.stringify({
							type: 'levelup',
							goodId: this.sid,
							goodName: this.sname,
							goodNumber: 1,
							goodPrice: this.price,
						})
					})
				}
			},
			
			handleRefreshBuyList () {
				let _t = this
				let buyList = {
					avatar: avatarUrl + '?t=' + new Date().getTime(),
					name: getRandMobile()
				}
				
				this.buyList = buyList
				this.timer && clearTimeout(this.timer)
				this.timer = setTimeout(() => {
					_t.handleRefreshBuyList()
				}, 3000)
			}
		}
	}
</script>

<style>
	page{
		background: #222222;
	}
</style>

<style lang="less">
	.container{
		padding-bottom: 40px;
	}
	
	.banner{
		width: 100%;
		position: relative;
		
		.pic{
			width: 100%;
		}
		
		.con{
			position: absolute;
			top: 206px;
			left: 0;
			width: 100%;
			display: flex;
			align-items: center;
			flex-direction: column;
			
			.avatar{
				width: 102px;
				height: 102px;
				border: 4px solid rgba(203,160,124,1);
				border-radius: 51px;
			}
			
			.name{
				font-size: 26px;
				color: #FFFFFF;
				margin-top: 16px;
			}
			
			.icon{
				width: 140px;
				height: 34px;
				margin-top: 6px;
			}
		}
	}
	
	.new{
		width: 610px;
		height: 56px;
		margin: 16px auto 0;
		border-radius: 28px;
		background: #333333;
		display: flex;
		align-items: center;
		box-sizing: border-box;
		padding: 0 6px;
		
		.avatar{
			width: 44px;
			height: 44px;
			border-radius: 22px;
			margin-right: 20px;
		}
		
		.name{
			font-size: 24px;
			color: #FFFFFF;
		}
	}
	
	.btn_go{
		width: 310px;
		height: 76px;
		background: linear-gradient(90deg,rgba(139,103,43,1) 0%,rgba(249,219,149,1) 51%,rgba(149,107,36,1) 100%);
		border-radius: 46px;
		font-size: 32px;
		color: 333;
		margin: 0 auto;
		text-align: center;
		line-height: 76px;
	}
	
	.f1{
		width: 670px;
		position: relative;
		margin: 60px auto 0;
		
		.pic{
			width: 100%;
			vertical-align: bottom;
		}
		
		.btn_go{
			position: absolute;
			bottom: 30px;
			left: 180px;
		}
	}
	
	.f2{
		width: 670px;
		position: relative;
		margin: 30px auto 0;
		background: #2D2D2D;
		border-radius: 20px;
		padding-top: 40px;
		padding-bottom: 60px;
		
		.pic{
			width: 582px;
			margin-left: 40px;
		}
		
		.ul{
			width: 590px;
			margin: 72px auto 0;
			
			.li{
				padding: 0 20px;
				height: 84px;
				display: flex;
				align-items: center;
				
				text{
					font-size: 26px;
					color: #FFFFFF;
				}
				
				&:nth-child(odd){
					background: #262626;
				}
			}
		}
		
		.btn_go{
			margin-top: 60px;
		}
	}
</style>
